package com.qire.manhua.model.vo;

import com.qire.common.basic.ObjectUtil;
import com.qire.common.basic.StringUtil;
import com.qire.common.support.base.BaseVO;
import com.qire.manhua.model.entity.ComicBookEntity;

public class ComicReadHistoryVO extends BaseVO {

    @Deprecated
    public int btype;                           //: 0,
    public BookInfoVO bookInfo;                 //: {},
    public LastReadChapterVO lastReadChapter;   //: {},
    public LastUpdateChapter lastUpdateChapter; //: {}

    public ComicBookEntity toComicBookEntity() {
        if(ObjectUtil.isNull(bookInfo)) {
            return null;
        }

        int lastReadChapterId = ObjectUtil.isNull(lastReadChapter) ? 0 : lastReadChapter.id;

        return new ComicBookEntity(bookInfo.id, bookInfo.book_name, lastReadChapterId, bookInfo.book_unruly);
    }

    public String lastReadRecord() {
        if (ObjectUtil.isNull(lastReadChapter) || StringUtil.isEmpty(lastReadChapter.chapter_name)) {
            return "";
        }
        return lastReadChapter.chapter_name;
    }

    public long lastUpdateTime() {
        if(ObjectUtil.isNull(lastUpdateChapter)) {
            return 0;
        }
        return lastUpdateChapter.create_time;
    }

    public String updateChapterInfo() {
        if(ObjectUtil.isNull(lastUpdateChapter) || StringUtil.isEmpty(lastUpdateChapter.chapter_name)) {
            return "";
        }
        String updateChapterInfo = lastUpdateChapter.chapter_name;
        int findIndex = updateChapterInfo.indexOf(" ");
        return findIndex > 0 ? updateChapterInfo.substring(0, findIndex) : updateChapterInfo;
    }

    public class BookInfoVO {
        public int id;                          //: 10961,
        public String book_name;                //: "娘子嫁到",
        public String book_unruly;              //: "https://p.qiremanhua.com/uploads/book/202005/5ecb97b863129.jpg"
    }

    public class LastReadChapterVO {
        public int id;                          //: 75702,
        public String chapter_name;             //: "第3话 薛家人可真奇怪"
    }

    public class LastUpdateChapter {
        public int id;                          //: 86576,
        public String chapter_name;             //: "第104话 做什么",
        public int chapter_px;                  //: 104,
        public long create_time;                //: 1603274328
    }

}
